package tech.aistar.service.center.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.UserInfo;
import tech.aistar.mapper.center.UserInfoMapper;
import tech.aistar.mapper.deamnd.PictureMapper;
import tech.aistar.service.center.IAddressService;
import tech.aistar.service.center.IUserInfoService;
import tech.aistar.service.position.IAreaService;
import tech.aistar.service.services.IServicesListService;

import java.util.List;

/**
 * Created by 23827 on 2019/9/28.
 */
@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private PictureMapper pictureMapper;
    @Autowired
    private IAreaService iAreaService;
    @Autowired
    private IServicesListService iServicesListService;
    @Autowired
    private IAddressService iAddressService;

    @Override
    public List<UserInfo> findAll() {
        List<UserInfo> list = userInfoMapper.findAll();
        return list;
    }

    @Override
    public UserInfo findByName(String name) {
        List<UserInfo> list2 = (List<UserInfo>) userInfoMapper.findByName(name);
        return (UserInfo) list2;
    }

    @Override
    public void updateUserInfo(UserInfo userInfo) {
        userInfoMapper.updateUserInfo(userInfo);
    }

    @Override
    public UserInfo insertUserInfo(UserInfo userInfo) {
        userInfoMapper.insertUserInfo(userInfo);
        return userInfo;
    }

    @Override
    public List<UserInfo> getById(Integer id) {
        List<UserInfo> list5 = userInfoMapper.getById(id);
        return list5;
    }

    @Override
    public UserInfo findById(Integer id) {
        UserInfo userInfo = userInfoMapper.findById(id);
        return userInfo;
    }

    @Override
    public UserInfo ById(Integer id) {
        UserInfo userInfo = userInfoMapper.ById(id);
        return userInfo;
    }

    @Override
    public UserInfo updateById(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
        return null;
    }

//    @Override
//    public CenterVo selectByUserId(Integer user_id) {
//        UserInfo userInfo = userInfoMapper.ById(user_id);
//        CenterVo centerVo = new CenterVo();
//        Picture picture = pictureMapper.findPathById(userInfo.getPictureId());
//        Address address = iAddressService.findByUserId(user_id);
//        centerVo.setUserId(userInfo.getUserId());
//        centerVo.setGrade(userInfo.getGrade());
//        centerVo.setTelNumber(userInfo.getTelNumber());
//        centerVo.setUrl(picture.getPath());
//        centerVo.setName(userInfo.getName());
//        centerVo.setProvinceName(address.getProvinceName());
//        centerVo.setCityName(address.getCityName());
//        centerVo.setAreaName(address.getAreaName());
//        centerVo.setAddressDeatil(address.getAddressDeatil());
//        centerVo.setDataFlag(address.getDataFlag());
//        centerVo.setIsDefault(address.getIsDefault());
//
//        return centerVo;
//    }

//    @Override
//    public List<CenterVo> centerVo(Integer id) {
//        List<UserInfo> userInfoList = userInfoMapper.getById(id);
//        List<Picture> pictureList =  pictureMapper.findById();
//        List<CenterVo> centerVoList = new ArrayList<>();
//        for (int i = 0; i <userInfoList.size() ; i++) {
//            CenterVo c = new CenterVo();
//            Picture p = pictureList.get(i);
//            UserInfo u = userInfoList.get(i);
//            //获取图片地址表的地址路径
//            String path = p.getPath();
//            c.setUrl(path);
//            //获取用户详细表的用户名
//            String name = u.getName();
//            c.setName(name);
//            //获取用户详细表的电话号码
//            String telNumber = u.getTelNumber();
//            c.setTelNumber(telNumber);
//            //获取用户详细表的等级
//            Integer grade = u.getGrade();
//            c.setGrade(grade);
//
//            centerVoList.add(c);
//
//        }
//
//        return centerVoList;
//    }



    @Override
    public UserInfo getByUserId(Integer id) {
        UserInfo userInfo = userInfoMapper.getByUserId(id);
        return userInfo;
    }

    @Override
    public UserInfo findNumberById(Integer id) {
        UserInfo userInfo = userInfoMapper.findNumberById(id);
        return userInfo;
    }

    @Override
    public UserInfo updateOne(UserInfo userInfo) {
        userInfoMapper.updateOne(userInfo);
        return userInfo;
    }
}
